package edu.dhbw.andar.sample;

import java.util.HashMap;

import org.cocos2d.nodes.CCSprite;
import org.cocos2d.nodes.CCSpriteFrame;
import org.cocos2d.nodes.CCSpriteSheet;
import org.cocos2d.types.CGPoint;
import org.cocos2d.types.CGRect;

/**Interface for steering the player's character*/
public class NFCFeedback {
	//Fields
	CCSprite _sprite;
	int _touchID;
	private HashMap<String, CCSpriteFrame> _contentFrames = new HashMap<String, CCSpriteFrame>();
	
	/**Constructor initializes graphics, position and touch*/
	public NFCFeedback(String imageFile, float startX, float startY){
		_sprite = CCSprite.sprite(imageFile);
		_sprite.setPosition(CGPoint.ccp(startX, startY));
		_touchID = -1;
		//Prepare action content icons
		CCSpriteSheet actionIcons = CCSpriteSheet.spriteSheet("pattern_spritesheet.png");
		_contentFrames.put("pokeylope",CCSpriteFrame.frame(
				actionIcons.getTexture(), CGRect.make(0, 0, 100, 100), CGPoint.ccp(88,  88)));
		_contentFrames.put("linda", CCSpriteFrame.frame(
				actionIcons.getTexture(), CGRect.make(100, 0, 100, 100), CGPoint.ccp(88,  88)));
		_contentFrames.put("oleander", CCSpriteFrame.frame(
				actionIcons.getTexture(), CGRect.make(200, 0, 100, 100), CGPoint.ccp(88, 88)));
		_contentFrames.put("harry", CCSpriteFrame.frame(
				actionIcons.getTexture(), CGRect.make(300, 0, 100, 100), CGPoint.ccp(88, 88)));
		_contentFrames.put("lens", CCSpriteFrame.frame(
				actionIcons.getTexture(), CGRect.make(400, 0, 100, 100), CGPoint.ccp(88, 88)));
		_contentFrames.put("shield", CCSpriteFrame.frame(
				actionIcons.getTexture(), CGRect.make(500, 0, 100, 100), CGPoint.ccp(88, 88)));
		_sprite.setVisible(false);
	}
	
	public void update(float dt){
	}
	
	/** */
	public void setImage(String image){
		if(_contentFrames.containsKey(image)){
			_sprite.setDisplayFrame(_contentFrames.get(image));
			_sprite.setVisible(true);
		} else {
			_sprite.setVisible(false);
		}
	}
	
	/** */
	public CCSprite getSprite(){
		return _sprite;
	}
	
	/** */
	public CGRect getRectangle(){
		return _sprite.getBoundingBox();
	}
	
	/** */
	public boolean isIntersecting(CGRect otherRect){
		return CGRect.intersects(_sprite.getBoundingBox(), otherRect);
	}
	
	/** */
	public boolean hasTouchID(int touchID){
		return _touchID == touchID;
	}
	
	/** */
	public void setTouchID(int touchID){
		_touchID = touchID;
	}
	
	/** */
	public int getTouchID(){
		return _touchID;
	}
	
	/** */
	public CGPoint getCenter(){
		return CGPoint.ccp(98, 98);
	}
	
	/** */
	public float getAngleTo(CGPoint point){
		return (float)Math.atan2(
				point.y - _sprite.getPosition().y,
				point.x - _sprite.getPosition().x);
	}
}
